package com.dream.common.utils.payutils;

import com.dream.common.utils.JsonUtils;
import com.dream.common.utils.payutils.bean.BeforeRedPackageBean;
import com.dream.common.utils.payutils.bean.configuration.*;
import com.dream.dto.request.GroupMemberBatchRequest;
import com.dream.entity.PickUserInfoBean;
import com.dream.common.utils.payutils.bean.WorkedRedPackageBean;
import com.dream.service.basic.BaseServiceHelper;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class WorkedRedPackageUtils {
    public static WorkedRedPackageBean getWorkedRedPackageBean(BeforeRedPackageBean beforeRedPackageBean, String forbidPickStr) {
        WorkedRedPackageBean workedRedPackageBean = new WorkedRedPackageBean();
        if (forbidPickStr == null || "".equals(forbidPickStr)) {
            workedRedPackageBean.isErrorRedPackage = true;
            workedRedPackageBean.errorRedPackageInfo = "未获取到襟枪頑珐配置"
                    + "\n1，登陆云算法官网"
                    + "\n2，打开賠率设置-襟枪頑珐"
                    + "\n3，设置群规";
            return workedRedPackageBean;
        }
        Data data = JsonUtils.parseObject(forbidPickStr, Data.class);
        if (data == null || data.data == null) {
            workedRedPackageBean.isErrorRedPackage = true;
            workedRedPackageBean.errorRedPackageInfo = "未获取到襟枪頑珐配置"
                    + "\n1，登陆云算法官网"
                    + "\n2，打开賠率设置-襟枪頑珐"
                    + "\n3，设置群规";
            return workedRedPackageBean;
        }
        ConfigurationBean configurationBean = data.data;
        workedRedPackageBean.bijiAccount = beforeRedPackageBean.userName;
        workedRedPackageBean.groupName = beforeRedPackageBean.groupName;
        workedRedPackageBean.groupID = beforeRedPackageBean.groupId;
        workedRedPackageBean.sendUserID = beforeRedPackageBean.sendId;
        workedRedPackageBean.sendUsername = beforeRedPackageBean.sendName;
        workedRedPackageBean.sendHeadImage = beforeRedPackageBean.sendHeadImg;
        workedRedPackageBean.redPackageID = beforeRedPackageBean.msgId;
        workedRedPackageBean.sendTime = System.currentTimeMillis();
        workedRedPackageBean.sendMoney = Double.parseDouble(beforeRedPackageBean.resultData.totalfee);
        workedRedPackageBean.sendNumber = beforeRedPackageBean.resultData.totalnum;

        workedRedPackageBean = setBasePickerInfo(workedRedPackageBean, beforeRedPackageBean.resultData.cxuserredpackagelist);
        if (workedRedPackageBean.isErrorRedPackage) {
            return workedRedPackageBean;
        }
        workedRedPackageBean = WishingUtils.setWishing(beforeRedPackageBean, workedRedPackageBean);
        workedRedPackageBean = WorkedRedPackageUtils.setPickUserList(workedRedPackageBean, beforeRedPackageBean, configurationBean);
        workedRedPackageBean = WorkedRedPackageUtils.setStealMoney(workedRedPackageBean);
        return workedRedPackageBean;
    }

    public static WorkedRedPackageBean checkFeatureSwitch(BeforeRedPackageBean beforeRedPackageBean, String featureSwitchString) {
        WorkedRedPackageBean workedRedPackageBean = new WorkedRedPackageBean();
        //未获取到功能开关界面设置，红包不处理
        if (featureSwitchString == null || "".equals(featureSwitchString)) {
            workedRedPackageBean.isErrorRedPackage = true;
            workedRedPackageBean.errorRedPackageInfo = "未获取到功能开关界面设置"
                    + "\n1，登陆云算法官网"
                    + "\n2，打开功能开关界面"
                    + "\n3，打开頑珐设置";
            return workedRedPackageBean;
        }
        FunctionSwitchBean functionSwitchBean = JsonUtils.parseObject(featureSwitchString, FunctionSwitchBean.class);
        if (functionSwitchBean == null) {
            workedRedPackageBean.isErrorRedPackage = true;
            workedRedPackageBean.errorRedPackageInfo = "未获取到功能开关界面设置"
                    + "\n1，登陆云算法官网"
                    + "\n2，打开功能开关界面"
                    + "\n3，打开頑珐设置";
            return workedRedPackageBean;
        }
        double sendMoney = Double.parseDouble(beforeRedPackageBean.resultData.totalfee);
        if (functionSwitchBean.packLimit > 0) {
            switch (functionSwitchBean.packLimit) {
                case 1:
                    if (sendMoney % 5 != 0) {
                        workedRedPackageBean.isErrorRedPackage = true;
                        workedRedPackageBean.errorRedPackageInfo = "不是整5伐包";
                        return workedRedPackageBean;
                    }
                    break;
                case 2:
                    if (sendMoney % 10 != 0) {
                        workedRedPackageBean.isErrorRedPackage = true;
                        workedRedPackageBean.errorRedPackageInfo = "不是整10伐包";
                        return workedRedPackageBean;
                    }
                    break;
                case 3:
                    if (sendMoney % 100 != 0) {
                        workedRedPackageBean.isErrorRedPackage = true;
                        workedRedPackageBean.errorRedPackageInfo = "不是整100伐包";
                        return workedRedPackageBean;
                    }
                    break;
                case 4:
                    if (sendMoney % 1 != 0) {
                        workedRedPackageBean.isErrorRedPackage = true;
                        workedRedPackageBean.errorRedPackageInfo = "不是整数伐包";
                        return workedRedPackageBean;
                    }
                    break;
            }
        }
        return workedRedPackageBean;
    }

    public static WorkedRedPackageBean setStealMoney(WorkedRedPackageBean workedRedPackageBean) {
        List<PickUserInfoBean> pickUserList = workedRedPackageBean.pickUserList;
        double stealMoney = 0;
        if (pickUserList != null) {
            for (PickUserInfoBean pickUserInfoBean : pickUserList) {
                if (pickUserInfoBean.isNoPicker) {
                    stealMoney = stealMoney + pickUserInfoBean.pickMoney;
                }
            }
        }
        workedRedPackageBean.stealMoney = stealMoney;
        return workedRedPackageBean;
    }


    public static WorkedRedPackageBean setPickUserList(WorkedRedPackageBean workedRedPackageBean, BeforeRedPackageBean beforeRedPackageBean, ConfigurationBean configurationBean) {
        String wishing = workedRedPackageBean.wishing;
        PlayDetailBean playDetailBean = null;
        int redPackageNumber = beforeRedPackageBean.resultData.totalnum;
        PackageBean packageBean = getPackageBean(redPackageNumber, configurationBean);
        if (packageBean == null) {
            workedRedPackageBean.isErrorRedPackage = true;
            workedRedPackageBean.errorRedPackageInfo = "未打开" + redPackageNumber + "包" + wishing.length() + "蕾頑珐"
                    + "\n1，登陆云算法官网"
                    + "\n2，打开賠率设置界面"
                    + "\n3，打开襟枪頑珐界面"
                    + "\n4，开启对应包数开关";

            return workedRedPackageBean;
        }
        if (packageBean.not.enable) {
            workedRedPackageBean.playType = 4;
        }
        if (workedRedPackageBean.playType == 4) {
            playDetailBean = packageBean.not;
            if (!playDetailBean.enable) {
                workedRedPackageBean.isErrorRedPackage = true;
                workedRedPackageBean.errorRedPackageInfo = "未打开" + redPackageNumber + "包不仲頑珐"
                        + "\n1，登陆云算法官网"
                        + "\n2，打开賠率设置界面"
                        + "\n3，打开襟枪頑珐界面"
                        + "\n4，开启对应包数不仲頑珐开关";
                return workedRedPackageBean;
            }
        } else {
            switch (redPackageNumber) {
                case 5:
                case 6:
                    switch (wishing.length()) {
                        case 1:
                            playDetailBean = packageBean.single;
                            workedRedPackageBean.playType = 1;
                            break;
                        default:
                            playDetailBean = packageBean.mix;
                            workedRedPackageBean.playType = 2;
                            break;
                    }
                    break;
                case 7:
                case 8:
                case 9:
                case 10:
                    switch (wishing.length()) {
                        case 1:
                            playDetailBean = packageBean.single;
                            workedRedPackageBean.playType = 1;
                            break;
                        case 2:
                            if (packageBean.two.enable) {
                                playDetailBean = packageBean.two;
                                workedRedPackageBean.playType = 3;
                            } else if (packageBean.mix.enable) {
                                playDetailBean = packageBean.mix;
                                workedRedPackageBean.playType = 2;
                            }
                            break;
                        case 3:
                            if (packageBean.three.enable) {
                                playDetailBean = packageBean.three;
                                workedRedPackageBean.playType = 3;
                            } else if (packageBean.mix.enable) {
                                playDetailBean = packageBean.mix;
                                workedRedPackageBean.playType = 2;
                            }
                            break;
                        case 4:
                            if (packageBean.four.enable) {
                                playDetailBean = packageBean.four;
                                workedRedPackageBean.playType = 3;
                            } else if (packageBean.mix.enable) {
                                playDetailBean = packageBean.mix;
                                workedRedPackageBean.playType = 2;
                            }
                            break;
                        case 5:
                            if (packageBean.five.enable) {
                                playDetailBean = packageBean.five;
                                workedRedPackageBean.playType = 3;
                            } else if (packageBean.mix.enable) {
                                playDetailBean = packageBean.mix;
                                workedRedPackageBean.playType = 2;
                            }
                            break;
                        case 6:
                            if (packageBean.six.enable) {
                                playDetailBean = packageBean.six;
                                workedRedPackageBean.playType = 3;
                            } else if (packageBean.mix.enable) {
                                playDetailBean = packageBean.mix;
                                workedRedPackageBean.playType = 2;
                            }
                            break;
                        case 7:
                            if (packageBean.seven.enable) {
                                playDetailBean = packageBean.seven;
                                workedRedPackageBean.playType = 3;
                            } else if (packageBean.mix.enable) {
                                playDetailBean = packageBean.mix;
                                workedRedPackageBean.playType = 2;
                            }
                            break;
                        case 8:
                            if (packageBean.eight.enable) {
                                playDetailBean = packageBean.six;
                                workedRedPackageBean.playType = 3;
                            } else if (packageBean.mix.enable) {
                                playDetailBean = packageBean.mix;
                                workedRedPackageBean.playType = 2;
                            }
                            break;
                    }
                    break;
            }
            if (playDetailBean == null || !playDetailBean.enable) {
                workedRedPackageBean.isErrorRedPackage = true;
                workedRedPackageBean.errorRedPackageInfo = "未打开'" + redPackageNumber + "包" + wishing.length() + "蕾'頑珐"
                        + "\n1，登陆云算法官网"
                        + "\n2，打开賠率设置界面"
                        + "\n3，打开襟枪頑珐界面"
                        + "\n4，开启对应包数开关";
                return workedRedPackageBean;
            }
        }
        if (playDetailBean != null) {
            double sendMoney = Double.parseDouble(beforeRedPackageBean.resultData.totalfee);
            if (sendMoney < playDetailBean.min || sendMoney > playDetailBean.max) {
                workedRedPackageBean.isErrorRedPackage = true;
                workedRedPackageBean.errorRedPackageInfo = "伐包琻额'" + sendMoney + "'未在'" + playDetailBean.min + "-" + playDetailBean.max + "'范围内";
                return workedRedPackageBean;
            }
            if (sendMoney >= playDetailBean.disableMin && sendMoney <= playDetailBean.disableMax && hasSameNumber(workedRedPackageBean.wishing, playDetailBean.disableNumber)) {
                workedRedPackageBean.isErrorRedPackage = true;
                workedRedPackageBean.errorRedPackageInfo = "襟'" + playDetailBean.disableNumber + "'，包名'" + workedRedPackageBean.wishing + "'有襟止数字";
                return workedRedPackageBean;
            }
            List<BeforeRedPackageBean.ResultData.Cxuserredpackagelist> pickUserList = beforeRedPackageBean.resultData.cxuserredpackagelist;
            workedRedPackageBean = setPickUserList(workedRedPackageBean, wishing, pickUserList, playDetailBean);
            if (workedRedPackageBean.playType == 4) {
                workedRedPackageBean = setNotThunderMoney(workedRedPackageBean, playDetailBean);
            } else {
                workedRedPackageBean = setThunderMoney(workedRedPackageBean, playDetailBean);
            }
        }
        return workedRedPackageBean;
    }

    private static WorkedRedPackageBean setPickUserList(WorkedRedPackageBean workedRedPackageBean, String wishing, List<BeforeRedPackageBean.ResultData.Cxuserredpackagelist> pickUserList, PlayDetailBean playDetailBean) {
        PlayDetailBean.NoDead noDead = playDetailBean.noDead;
        if (noDead == null) {
            noDead = new PlayDetailBean.NoDead();
        }
        workedRedPackageBean = setLuckiest(workedRedPackageBean, pickUserList);
        workedRedPackageBean = setNoDead(workedRedPackageBean, noDead);
        workedRedPackageBean = setThunder(workedRedPackageBean, wishing);
        workedRedPackageBean = setNoPick(workedRedPackageBean);
        return workedRedPackageBean;
    }

    private static WorkedRedPackageBean setNoPick(WorkedRedPackageBean workedRedPackageBean) {
        GroupMemberBatchRequest batchRequest = BaseServiceHelper.getProcedureServiceImpl().getMemberRoles(workedRedPackageBean.bijiAccount);
        //batchRequest 不可能为空不需要判断、roleMap不可能为空，
        //!CollectionUtils.isEmpty(batchRequest.roleMap) 判断empty即可
        if (batchRequest == null || batchRequest.roleMap == null || batchRequest.roleMap.get("touchPackList") == null || batchRequest.roleMap.get("touchPackList").size() == 0) {
            for (PickUserInfoBean pickUserInfoBean : workedRedPackageBean.pickUserList) {
                pickUserInfoBean.isNoPicker = true;
            }
            return workedRedPackageBean;
        }
        for (PickUserInfoBean pickUserInfoBean : workedRedPackageBean.pickUserList) {
            if (!batchRequest.roleMap.get("touchPackList").contains(pickUserInfoBean.userID)) {
                pickUserInfoBean.isNoPicker = true;
            }
        }
        return workedRedPackageBean;
    }

    private static WorkedRedPackageBean setNotThunderMoney(WorkedRedPackageBean workedRedPackageBean, PlayDetailBean playDetailBean) {
        if (!workedRedPackageBean.isWin) {
            workedRedPackageBean.thunderMoney = 0.0;
        } else {
            double multiple = 0;
            switch (workedRedPackageBean.wishing.length()) {
                case 1:
                    multiple = playDetailBean.one;
                    break;
                case 2:
                    multiple = playDetailBean.two;
                    break;
                case 3:
                    multiple = playDetailBean.three;
                    break;
                case 4:
                    multiple = playDetailBean.four;
                    break;
                case 5:
                    multiple = playDetailBean.five;
                    break;
                case 6:
                    multiple = playDetailBean.six;
                    break;
                case 7:
                    multiple = playDetailBean.seven;
                    break;
                case 8:
                    multiple = playDetailBean.eight;
                    break;
                case 9:
                    multiple = playDetailBean.nine;
                    break;
                case 10:
                    multiple = playDetailBean.ten;
                    break;
            }
            double thunderMoney = NumberUtils.multiply(workedRedPackageBean.sendMoney, multiple);
            workedRedPackageBean.thunderMoney = thunderMoney;
        }
        return workedRedPackageBean;
    }

    private static WorkedRedPackageBean setThunderMoney(WorkedRedPackageBean workedRedPackageBean, PlayDetailBean playDetailBean) {
        if (!workedRedPackageBean.isWin) {
            workedRedPackageBean.thunderMoney = 0.0;
        } else {
            double thunderMoney = 0;
            int thunderNumber = 0;
            for (PickUserInfoBean pickUserInfoBean : workedRedPackageBean.pickUserList) {
                if (pickUserInfoBean.isThunder) {
                    thunderNumber = thunderNumber + 1;
                }
            }
            double multiple = 0;
            int number = 0;
            switch (workedRedPackageBean.pickUserList.size()) {
                case 5:
                case 6:
                    switch (workedRedPackageBean.playType) {
                        case 1://単蕾
                            number = thunderNumber;
                            break;
                        case 2://组合
                            number = workedRedPackageBean.wishing.length();
                            break;
                    }
                    switch (number) {
                        case 1:
//                        boolean noDeadOnlyThunder;
//                        for (PickUserInfoBean pickUserInfoBean : workedRedPackageBean.pickUserList){
//                            if(pickUserInfoBean.isNoDead && pickUserInfoBean.isThunder){
//                                noDeadOnlyThunder = true;
//                            }
//                        }
                            multiple = playDetailBean.one;
                            break;
                        case 2:
                            multiple = playDetailBean.two;
                            break;
                        case 3:
                            multiple = playDetailBean.three;
                            break;
                        case 4:
                            multiple = playDetailBean.four;
                            break;
                        case 5:
                            multiple = playDetailBean.five;
                            break;
                        case 6:
                            multiple = playDetailBean.six;
                            break;
                    }
                    thunderMoney = NumberUtils.multiply(workedRedPackageBean.sendMoney, multiple);
                    break;
                case 7:
                case 8:
                case 9:
                case 10:
                    if (workedRedPackageBean.playType == 1 || workedRedPackageBean.playType == 2) {//単蕾或者组合頑珐
                        if (workedRedPackageBean.playType == 1) {
                            number = thunderNumber;
                        } else if (workedRedPackageBean.playType == 2) {
                            number = workedRedPackageBean.wishing.length();
                        }
                        switch (number) {
                            case 1:
                                multiple = playDetailBean.one;
                                break;
                            case 2:
                                if (playDetailBean.twoCompare != null && "BIG_THAN".equals(playDetailBean.twoCompare.type) && workedRedPackageBean.sendMoney >= playDetailBean.twoCompare.amount && playDetailBean.twoCompare.amount != 0) {
                                    multiple = playDetailBean.twoCompare.multiple;
                                } else if (playDetailBean.twoCompare != null && "SMALL_THAN".equals(playDetailBean.twoCompare.type) && workedRedPackageBean.sendMoney <= playDetailBean.twoCompare.amount && playDetailBean.twoCompare.amount != 0) {
                                    multiple = playDetailBean.twoCompare.multiple;
                                } else {
                                    multiple = playDetailBean.two;
                                }
                                break;
                            case 3:
                                if (playDetailBean.threeCompare != null && "BIG_THAN".equals(playDetailBean.threeCompare.type) && workedRedPackageBean.sendMoney >= playDetailBean.threeCompare.amount && playDetailBean.threeCompare.amount != 0) {
                                    multiple = playDetailBean.threeCompare.multiple;
                                } else if (playDetailBean.threeCompare != null && "SMALL_THAN".equals(playDetailBean.threeCompare.type) && workedRedPackageBean.sendMoney <= playDetailBean.threeCompare.amount && playDetailBean.threeCompare.amount != 0) {
                                    multiple = playDetailBean.threeCompare.multiple;
                                } else {
                                    multiple = playDetailBean.three;
                                }
                                break;
                            case 4:
                                if (playDetailBean.fourCompare != null && "BIG_THAN".equals(playDetailBean.fourCompare.type) && workedRedPackageBean.sendMoney >= playDetailBean.fourCompare.amount && playDetailBean.fourCompare.amount != 0) {
                                    multiple = playDetailBean.fourCompare.multiple;
                                } else if (playDetailBean.fourCompare != null && "SMALL_THAN".equals(playDetailBean.fourCompare.type) && workedRedPackageBean.sendMoney <= playDetailBean.fourCompare.amount && playDetailBean.fourCompare.amount != 0) {
                                    multiple = playDetailBean.fourCompare.multiple;
                                } else {
                                    multiple = playDetailBean.four;
                                }
                                break;
                            case 5:
                                if (playDetailBean.fiveCompare != null && "BIG_THAN".equals(playDetailBean.fiveCompare.type) && workedRedPackageBean.sendMoney >= playDetailBean.fiveCompare.amount && playDetailBean.fiveCompare.amount != 0) {
                                    multiple = playDetailBean.fiveCompare.multiple;
                                } else if (playDetailBean.fiveCompare != null && "SMALL_THAN".equals(playDetailBean.fiveCompare.type) && workedRedPackageBean.sendMoney <= playDetailBean.fiveCompare.amount && playDetailBean.fiveCompare.amount != 0) {
                                    multiple = playDetailBean.fiveCompare.multiple;
                                } else {
                                    multiple = playDetailBean.five;
                                }
                                break;
                            case 6:
                                if (playDetailBean.sixCompare != null && "BIG_THAN".equals(playDetailBean.sixCompare.type) && workedRedPackageBean.sendMoney >= playDetailBean.sixCompare.amount && playDetailBean.sixCompare.amount != 0) {
                                    multiple = playDetailBean.sixCompare.multiple;
                                } else if (playDetailBean.sixCompare != null && "SMALL_THAN".equals(playDetailBean.sixCompare.type) && workedRedPackageBean.sendMoney <= playDetailBean.sixCompare.amount && playDetailBean.sixCompare.amount != 0) {
                                    multiple = playDetailBean.sixCompare.multiple;
                                } else {
                                    multiple = playDetailBean.six;
                                }
                                break;
                            case 7:
                                if (playDetailBean.sevenCompare != null && "BIG_THAN".equals(playDetailBean.sevenCompare.type) && workedRedPackageBean.sendMoney >= playDetailBean.sevenCompare.amount && playDetailBean.sevenCompare.amount != 0) {
                                    multiple = playDetailBean.sevenCompare.multiple;
                                } else if (playDetailBean.sevenCompare != null && "SMALL_THAN".equals(playDetailBean.sevenCompare.type) && workedRedPackageBean.sendMoney <= playDetailBean.sevenCompare.amount && playDetailBean.sevenCompare.amount != 0) {
                                    multiple = playDetailBean.sevenCompare.multiple;
                                } else {
                                    multiple = playDetailBean.seven;
                                }
                                break;
                            case 8:
                                if (playDetailBean.eightCompare != null && "BIG_THAN".equals(playDetailBean.eightCompare.type) && workedRedPackageBean.sendMoney >= playDetailBean.eightCompare.amount && playDetailBean.eightCompare.amount != 0) {
                                    multiple = playDetailBean.eightCompare.multiple;
                                } else if (playDetailBean.eightCompare != null && "SMALL_THAN".equals(playDetailBean.eightCompare.type) && workedRedPackageBean.sendMoney <= playDetailBean.eightCompare.amount && playDetailBean.eightCompare.amount != 0) {
                                    multiple = playDetailBean.eightCompare.multiple;
                                } else {
                                    multiple = playDetailBean.eight;
                                }
                                break;
                            case 9:
                                if (playDetailBean.nineCompare != null && "BIG_THAN".equals(playDetailBean.nineCompare.type) && workedRedPackageBean.sendMoney >= playDetailBean.nineCompare.amount && playDetailBean.nineCompare.amount != 0) {
                                    multiple = playDetailBean.nineCompare.multiple;
                                } else if (playDetailBean.nineCompare != null && "SMALL_THAN".equals(playDetailBean.nineCompare.type) && workedRedPackageBean.sendMoney <= playDetailBean.nineCompare.amount && playDetailBean.nineCompare.amount != 0) {
                                    multiple = playDetailBean.nineCompare.multiple;
                                } else {
                                    multiple = playDetailBean.nine;
                                }
                                break;
                            case 10:
                                if (playDetailBean.tenCompare != null && "BIG_THAN".equals(playDetailBean.tenCompare.type) && workedRedPackageBean.sendMoney >= playDetailBean.tenCompare.amount && playDetailBean.tenCompare.amount != 0) {
                                    multiple = playDetailBean.tenCompare.multiple;
                                } else if (playDetailBean.tenCompare != null && "SMALL_THAN".equals(playDetailBean.tenCompare.type) && workedRedPackageBean.sendMoney <= playDetailBean.tenCompare.amount && playDetailBean.tenCompare.amount != 0) {
                                    multiple = playDetailBean.tenCompare.multiple;
                                } else {
                                    multiple = playDetailBean.ten;
                                }
                                break;
                        }
                        thunderMoney = NumberUtils.multiply(workedRedPackageBean.sendMoney, multiple);
                    } else {//哆蕾頑珐
                        List<PlayDetailBean.AmountOddItem> amountOddsList = playDetailBean.amountOdds;
                        boolean isInSpecialMoney = false;
                        PlayDetailBean.AmountOddItem currentAmountOddItem = null;
                        for (PlayDetailBean.AmountOddItem amountOddItem : amountOddsList) {
                            if (workedRedPackageBean.sendMoney >= amountOddItem.min && workedRedPackageBean.sendMoney <= amountOddItem.max) {
                                isInSpecialMoney = true;
                                currentAmountOddItem = amountOddItem;
                                break;
                            }
                        }
                        if (isInSpecialMoney && currentAmountOddItem != null) {
//                            multiple = NumberUtils.multiply(currentAmountOddItem.multiple, thunderNumber);襟枪
                            multiple = currentAmountOddItem.multiple;
                        } else {
//                            multiple = NumberUtils.multiply(playDetailBean.multiple, thunderNumber);襟枪
                            multiple = playDetailBean.multiple;
                        }
                        thunderMoney = NumberUtils.multiply(workedRedPackageBean.sendMoney, NumberUtils.multiply(thunderNumber, multiple));
                        switch (thunderNumber) {
                            case 2:
                                if ("MULTIPLE".equals(playDetailBean.twoType)) {
                                    thunderMoney = NumberUtils.add(thunderMoney, NumberUtils.multiply(workedRedPackageBean.sendMoney, playDetailBean.two));
                                } else {
                                    thunderMoney = NumberUtils.add(thunderMoney, playDetailBean.two);
                                }
                                break;
                            case 3:
                                if ("MULTIPLE".equals(playDetailBean.threeType)) {
                                    thunderMoney = NumberUtils.add(thunderMoney, NumberUtils.multiply(workedRedPackageBean.sendMoney, playDetailBean.three));
                                } else {
                                    thunderMoney = NumberUtils.add(thunderMoney, playDetailBean.three);
                                }
                                break;
                            case 4:
                                if ("MULTIPLE".equals(playDetailBean.fourType)) {
                                    thunderMoney = NumberUtils.add(thunderMoney, NumberUtils.multiply(workedRedPackageBean.sendMoney, playDetailBean.four));
                                } else {
                                    thunderMoney = NumberUtils.add(thunderMoney, playDetailBean.four);
                                }
                                break;
                            case 5:
                                if ("MULTIPLE".equals(playDetailBean.fiveType)) {
                                    thunderMoney = NumberUtils.add(thunderMoney, NumberUtils.multiply(workedRedPackageBean.sendMoney, playDetailBean.five));
                                } else {
                                    thunderMoney = NumberUtils.add(thunderMoney, playDetailBean.five);
                                }
                                break;
                            case 6:
                                if ("MULTIPLE".equals(playDetailBean.sixType)) {
                                    thunderMoney = NumberUtils.add(thunderMoney, NumberUtils.multiply(workedRedPackageBean.sendMoney, playDetailBean.six));
                                } else {
                                    thunderMoney = NumberUtils.add(thunderMoney, playDetailBean.six);
                                }
                                break;
                            case 7:
                                if ("MULTIPLE".equals(playDetailBean.sevenType)) {
                                    thunderMoney = NumberUtils.add(thunderMoney, NumberUtils.multiply(workedRedPackageBean.sendMoney, playDetailBean.seven));
                                } else {
                                    thunderMoney = NumberUtils.add(thunderMoney, playDetailBean.seven);
                                }
                                break;
                            case 8:
                                if ("MULTIPLE".equals(playDetailBean.eightType)) {
                                    thunderMoney = NumberUtils.add(thunderMoney, NumberUtils.multiply(workedRedPackageBean.sendMoney, playDetailBean.eight));
                                } else {
                                    thunderMoney = NumberUtils.add(thunderMoney, playDetailBean.eight);
                                }
                                break;
                            case 9:
                                if ("MULTIPLE".equals(playDetailBean.nineType)) {
                                    thunderMoney = NumberUtils.add(thunderMoney, NumberUtils.multiply(workedRedPackageBean.sendMoney, playDetailBean.nine));
                                } else {
                                    thunderMoney = NumberUtils.add(thunderMoney, playDetailBean.nine);
                                }
                                break;
                            case 10:
                                if ("MULTIPLE".equals(playDetailBean.tenType)) {
                                    thunderMoney = NumberUtils.add(thunderMoney, NumberUtils.multiply(workedRedPackageBean.sendMoney, playDetailBean.ten));
                                } else {
                                    thunderMoney = NumberUtils.add(thunderMoney, playDetailBean.ten);
                                }
                                break;
                        }
                        break;
                    }
                    break;
            }
            workedRedPackageBean.thunderMoney = thunderMoney;
        }
        return workedRedPackageBean;
    }

    private static WorkedRedPackageBean setBasePickerInfo(WorkedRedPackageBean workedRedPackageBean, List<BeforeRedPackageBean.ResultData.Cxuserredpackagelist> pickUserList) {
        DecimalFormat df = new DecimalFormat("##0.00");
        List<PickUserInfoBean> workedPickUserList = new ArrayList<>();
        for (int i = 0; i < pickUserList.size(); i++) {
            BeforeRedPackageBean.ResultData.Cxuserredpackagelist beforePickUser = pickUserList.get(i);
            PickUserInfoBean pickUserInfoBean = new PickUserInfoBean();
            pickUserInfoBean.bijiAccount = workedRedPackageBean.bijiAccount;
            pickUserInfoBean.userID = beforePickUser.taccid;
            pickUserInfoBean.username = beforePickUser.tname;
            pickUserInfoBean.userHeadImage = beforePickUser.ticon;
            pickUserInfoBean.pickTime = beforePickUser.endtime;
            pickUserInfoBean.pickMoney = beforePickUser.money;
            pickUserInfoBean.floor = i + 1;
            workedPickUserList.add(pickUserInfoBean);
        }
        workedRedPackageBean.pickUserList = workedPickUserList;
        return workedRedPackageBean;
    }

    private static WorkedRedPackageBean setNoDead(WorkedRedPackageBean workedRedPackageBean, PlayDetailBean.NoDead noDead) {
        List<PickUserInfoBean> workedPickUserList = workedRedPackageBean.pickUserList;
        for (int i = 0; i < workedPickUserList.size(); i++) {
            PickUserInfoBean pickUserInfoBean = workedPickUserList.get(i);
            if (noDead.noDeadType == 1) {
                int noDeadFloor = noDead.noDeadFloor;
                if (i + 1 == noDeadFloor) {
                    pickUserInfoBean.isNoDead = true;
                }
            } else if (noDead.noDeadType == 2) {
                if (pickUserInfoBean.userID.equals(noDead.noDeadID)) {
                    pickUserInfoBean.isNoDead = true;
                }
            } else if (noDead.noDeadType == 3) {
                if (pickUserInfoBean.isLuckiest) {
                    pickUserInfoBean.isNoDead = true;
                }
            }
        }
        workedRedPackageBean.pickUserList = workedPickUserList;
        return workedRedPackageBean;
    }

    private static WorkedRedPackageBean setLuckiest(WorkedRedPackageBean workedRedPackageBean, List<BeforeRedPackageBean.ResultData.Cxuserredpackagelist> pickUserList) {
        List<PickUserInfoBean> workedPickUserList = workedRedPackageBean.pickUserList;
        String luckiestUserID = pickUserList.get(0).taccid;
        double luckiestUserMoney = pickUserList.get(0).money;
        if (pickUserList.size() > 1) {
            for (int i = 0; i < pickUserList.size() - 1; i++) {
                if (pickUserList.get(i + 1).money > luckiestUserMoney) {
                    luckiestUserID = pickUserList.get(i + 1).taccid;
                    luckiestUserMoney = pickUserList.get(i + 1).money;
                }
            }
        }
        for (PickUserInfoBean pickUserInfoBean : workedPickUserList) {
            if (pickUserInfoBean.userID.equals(luckiestUserID)) {
                pickUserInfoBean.isLuckiest = true;
            }
        }
        workedRedPackageBean.pickUserList = workedPickUserList;
        return workedRedPackageBean;
    }

    private static WorkedRedPackageBean setThunder(WorkedRedPackageBean workedRedPackageBean, String wishing) {
        List<PickUserInfoBean> workedPickUserList = workedRedPackageBean.pickUserList;
        String allFen = "";
        boolean isShoot = true;
        for (int i = 0; i < workedPickUserList.size(); i++) {
            PickUserInfoBean pickUserInfoBean = workedPickUserList.get(i);
            allFen = allFen + NumberUtils.getFen(pickUserInfoBean.pickMoney);
        }
        char[] wishingChar = wishing.toCharArray();
        if (workedRedPackageBean.playType == 4) {
            for (char c : wishingChar) {
                if (allFen.contains(String.valueOf(c))) {
                    isShoot = false;
                    break;
                }
            }
        } else {
            for (char c : wishingChar) {
                if (!allFen.contains(String.valueOf(c))) {
                    isShoot = false;
                    break;
                }
            }
            if (isShoot) {
                for (int i = 0; i < workedPickUserList.size(); i++) {
                    PickUserInfoBean pickUserInfoBean = workedPickUserList.get(i);
                    double pickMoney = pickUserInfoBean.pickMoney;
                    String fen = (int)NumberUtils.multiply(pickMoney, 100) % 10 + "";
                    if (wishing.contains(fen) && !pickUserInfoBean.isNoDead) {
                        pickUserInfoBean.isThunder = true;
                    }
                }
            }
            workedRedPackageBean.pickUserList = workedPickUserList;
        }
        workedRedPackageBean.isWin = isShoot;
        return workedRedPackageBean;
    }

    private static PackageBean getPackageBean(int packageNumber, ConfigurationBean configurationBean) {
        PackageBean packageBean = null;
        switch (packageNumber) {
            case 5:
                packageBean = configurationBean.five;
                break;
            case 6:
                packageBean = configurationBean.six;
                break;
            case 7:
                packageBean = configurationBean.seven;
                break;
            case 8:
                packageBean = configurationBean.eight;
                break;
            case 9:
                packageBean = configurationBean.nine;
                break;
            case 10:
                packageBean = configurationBean.ten;
                break;
        }
        return packageBean;
    }

    private static boolean hasSameNumber(String wishing, String forbidNumber) {
        boolean hasSameNumber = false;
        char[] chars = wishing.toCharArray();
        for (char number : chars) {
            if (forbidNumber.contains(String.valueOf(number))) {
                hasSameNumber = true;
                break;
            }
        }
        return hasSameNumber;
    }
}
